package com.onlinesys.action;

import java.sql.SQLException;
import java.util.List;

import com.onlinesys.beans.ClassInfo;
import com.onlinesys.service.ClassService;
import com.onlinesys.service.impl.ClassServiceImpl;
import com.opensymphony.xwork2.ActionSupport;

public class ClassMgrAction extends ActionSupport {
    private static final long serialVersionUID = 1L;

    private List<ClassInfo> css = null;

    private int id;
    
    private String className = null;
    
    private String monitor = null;

    private String msg = null;
    
    public String execute() throws Exception {
        ClassService service = new ClassServiceImpl();
        css = service.getClassInfo();
        return SUCCESS;
    }
    
    public String addClass() throws Exception {
        ClassService service = new ClassServiceImpl();
        ClassInfo clazz = new ClassInfo();
        clazz.setId(id);
        clazz.setClassName(className);
        clazz.setMonitor(monitor);
        service.addNewClassInfo(clazz);
        try {
            css = service.getClassInfo();
        } catch(SQLException e) {
            msg = e.getLocalizedMessage();
        }
        return SUCCESS;
    }

    public String deleteClass() throws Exception {
        ClassService service = new ClassServiceImpl();
        service.deleteClassInfo(id);
        css = service.getClassInfo();
        return SUCCESS;
    }
    
    public String editClass() throws Exception {
        ClassService service = new ClassServiceImpl();
        ClassInfo clazz = new ClassInfo();
        clazz.setId(id);
        clazz.setClassName(className);
        clazz.setMonitor(monitor);
        service.updateClassInfo(clazz);
        css = service.getClassInfo();
        return SUCCESS;
    }

    public List<ClassInfo> getCss() {
        return css;
    }

    public void setCss(List<ClassInfo> css) {
        this.css = css;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public String getMonitor() {
        return monitor;
    }

    public void setMonitor(String monitor) {
        this.monitor = monitor;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

}
